from django.db import models
from django.contrib.auth.models import AbstractUser, UserManager as _UserManager


# Create your models here.

class UserManager(_UserManager):
    def create_superuser(self, username, password,email=None, **extra_fields):
        super().create_superuser(username=username,password=password,email=email,**extra_fields)

class User(AbstractUser):
    mobile = models.CharField(max_length=11, unique=True, verbose_name='手机号', help_text='手机号',
                              error_messages={'unique': '手机号已被注册'})

    email_active = models.BooleanField(default=False, verbose_name='邮箱验证')

    REQUIRED_FIELDS = ['mobile']

    objects = UserManager()

    class Meta:
        db_table = 'tb_user'  # 数据库的表名
        verbose_name = 'user'
        verbose_name_plural = 'users'

    def __str__(self):
        return '<%s:%s>'%(self.username,self.mobile)
